/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import java.io.File;

/**
 * <p>Project: JavaStudy - FileGetName
 * <p>Powered by jiangbo On 2023-01-03
 * 20:17:32
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class FileGetName {
    public static void main(String[] args) {
        String fs = "test.png";
        File file = new File(fs);
        System.out.println(file.length());
        System.out.println(file.exists());
        System.out.println(file.isFile());
        //获取时间
        System.out.println(String.format("%tF %<tT",file.lastModified()));
//获取文件的文件名
        System.out.println(file.getName());//test.png
//基本名
        String filename = file.getName();
        String basename = filename.contains(".") ? filename.substring(0,filename.lastIndexOf(".")) : filename;
        System.out.println(basename);
        //扩展名
        String ext = filename.contains(".") ? filename.substring(filename.lastIndexOf(".")+1) : "";
        System.out.println(ext);
//所在目录
        String abs = file.getAbsolutePath();
        String path = abs.substring(0,abs.lastIndexOf(File.separator)+1);
        System.out.println(path);
//详细路径
        System.out.println(file.getAbsoluteFile());//G:\anzhuanranjian\Java program\JavaStudy\test.png
        System.out.println(file.getAbsolutePath());//G:\anzhuanranjian\Java program\JavaStudy\test.png
        System.out.println(file.getPath());//test.png
    }
}


